package com.example.tests;

import java.util.Random;
import java.util.Set;

import static org.testng.Assert.*;

import org.testng.annotations.Test;

import com.example.data.ContactData;

public class ContactModificationTests extends TestBase {
	@Test
	public void contactModifyTest() throws Exception {
		//first go to home page and get list of contacts
		Set<ContactData> oldList = manager.getContactHelper().getContactsList();
		//continue test if contact list is not empty
		int oldListSize = oldList.size();
		if (oldListSize > 0) {
			Random rnd = new Random();
			int numberOfContactToModify = rnd.nextInt(oldListSize);
			int numOfDigits = 4;
			//init contact
			ContactData newContact = new ContactData()
			.setAddress("Address "+rnd.nextInt(numOfDigits))
			.setAddress2("Address2 "+rnd.nextInt(numOfDigits))
			.setDay("23")
			.setEmail1("Email1 "+rnd.nextInt(numOfDigits))
			.setEmail2("Email2 "+rnd.nextInt(numOfDigits))
			.setFirstName("FirstName "+rnd.nextInt(numOfDigits))
			.setHome2("Home2 "+rnd.nextInt(numOfDigits))
			.setHomeTel("HomeTel "+rnd.nextInt(numOfDigits))
			.setLastName("LastName "+rnd.nextInt(numOfDigits))
			.setMobileTel("MobileTel "+rnd.nextInt(numOfDigits))
			.setMonth("May")
			.setWorkTel("WorkTel "+rnd.nextInt(numOfDigits))
			.setYear("1");
			//modify contact
			ContactData contactToModify = manager.getContactHelper().modifyContactAndGetContactToModify(numberOfContactToModify , newContact );
			//get new list of contacts again
			Set<ContactData> newList = manager.getContactHelper().getContactsList();
			//compare lists
			verifyContactChanged(oldList, contactToModify, newContact, newList);
		} else {
			//fail the test if contact list is empty
			fail("Contacts list is empty");
		}

	}

}
